import java.util.Random;

public class Lab_01 {
    public static void main(String[] args) {
        Random random = new Random();
        
        System.out.println("50道100以内的加减法口算题：");
        System.out.println("============================");
        
        for (int i = 1; i <= 50; i++) {
            // 生成两个0-100之间的随机数
            int num1 = random.nextInt(101);
            int num2 = random.nextInt(101);
            
            // 随机决定是加法还是减法（0表示加法，1表示减法）
            int operation = random.nextInt(2);
            
            // 如果是减法且第一个数小于第二个数，则交换两数
            if (operation == 1 && num1 < num2) {
                int temp = num1;
                num1 = num2;
                num2 = temp;
            }
            
            // 计算正确答案
            int correctAnswer;
            String operator;
            
            if (operation == 0) {
                correctAnswer = num1 + num2;
                operator = "+";
            } else {
                correctAnswer = num1 - num2;
                operator = "-";
            }
            
            // 显示题目和答案
            System.out.printf("%2d. %d %s %d = %d%n", i, num1, operator, num2, correctAnswer);
        }
        
        System.out.println("============================");
        System.out.println("完成！所有题目及答案已显示。");
    }
}